﻿<Window x:Class="Caffeine.Examples.Contacts.View.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:system="clr-namespace:System;assembly=mscorlib"
        xmlns:controls="clr-namespace:System.Windows;assembly=PresentationCore"
        xmlns:caffeine="clr-namespace:Caffeine.Core;assembly=Caffeine.Core"
        xmlns:caffeineWpf="clr-namespace:Caffeine.Wpf;assembly=Caffeine.Wpf"
        xmlns:contacts="clr-namespace:Caffeine.Examples.Contacts.ViewModel"
        xmlns:contactViews="clr-namespace:Caffeine.Examples.Contacts.View"
        SnapsToDevicePixels="True"
        Title="MainWindow" 
        MinWidth="650" 
        MinHeight="600" 
        Name="ParentContainer" 
        Background="#333333"
        SizeToContent="WidthAndHeight">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="275" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="60" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Border Grid.ColumnSpan="2" Padding="20,10,0,0">
            <TextBlock FontSize="30" FontWeight="ExtraBlack" Foreground="LightGray">Contact Manager</TextBlock>
        </Border>
        <Grid Grid.Row="1" Margin="10">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="20" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <WrapPanel HorizontalAlignment="Right" Grid.ColumnSpan="2" Margin="0,0,20,5">
                <WrapPanel.Resources>
                    <Style TargetType="Button">
                        <Setter Property="Margin" Value="0,0,5,0" />
                    </Style>
                </WrapPanel.Resources>
                <Button Content="Save All" 
                        Command="{Binding SaveContacts}" 
                        Style="{StaticResource SaveButton}"
                        ToolTip="Save All Changes" />
                <Button Margin="5,5,0,0"
                        Command="{Binding UndoContactChanges}"
                        ToolTip="Undo Changes">
                    <Button.Style>
                        <Style TargetType="Button" BasedOn="{StaticResource UndoButton}">
                            <Setter Property="Visibility" Value="Collapsed" />
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding IsDirty}" Value="True">
                                    <Setter Property="Visibility" Value="Visible" />
                                </DataTrigger>
                                <DataTrigger Binding="{Binding IsDirtyWithin}" Value="True">
                                    <Setter Property="Visibility" Value="Visible" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Button.Style>
                </Button>
                <Button Content="Add" 
                        Command="{Binding AddContact}" 
                        Style="{DynamicResource AddButton}" 
                        ToolTip="Add New Contact" 
                        Margin="10,0,0,0" />
            </WrapPanel>
            <ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Row="1" Grid.Column="1">
                <contactViews:ContactListWrapper>
                    <ItemsControl HorizontalAlignment="Stretch" ItemsSource="{Binding Contacts}">
                        <ItemsControl.Resources>
                            <DataTemplate DataType="{x:Type contacts:ContactViewModel}">
                                <contactViews:ContactSnapshotView />
                            </DataTemplate>
                        </ItemsControl.Resources>
                    </ItemsControl>
                </contactViews:ContactListWrapper>
            </ScrollViewer>
        </Grid>
        <Border Visibility="{Binding Path=IsContactSelected, Converter={StaticResource BooleanToVisibilityConverter}}"
                Grid.Row="1" 
                Grid.Column="1"
                Margin="0,0,5,5">
            <contactViews:ContactView DataContext="{Binding SelectedContact.Value}" />
        </Border>
    </Grid>
</Window>
